function getData() {
  // js 中发送接口请求
  return new Promise((resolve) => {
    const xhr = new XMLHttpRequest()
    // 准备请求参数
    xhr.open('GET', 'https://mock.mengxuegu.com/mock/6767738f98077b17fe6792e2/question-naire', true)
    // 发送请求
    xhr.send()
    // 监听请求的不同状态
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4 && xhr.status == 200) {
        // console.log(xhr.responseText);
        const data = JSON.parse(xhr.responseText) // 将数据的格式处理成json 格式
        // console.log(data.questions);
        resolve(data.questions)
      }
    }
  })

}

getData().then((res) => {
    console.log(res);

    //修改head
    const head = document.getElementById('totalNum');
    head.innerHTML = res.length;
    const barProgess = document.querySelector('.bar-progess')
    barProgess.style.width = (1 / res.length) * 100 + '%'

    //展示题目
    showQuestion(res,1);

})
function showQuestion(arr,current){
    console.log(arr);
    const num = document.getElementById('num');
    num.innerHTML = current;

    console.log(arr[0]);

    //修改问题
    const questionTitle = document.querySelector('.question-title')
    questionTitle.innerText = arr[current - 1].topic_name

    //设置答案
    topic_answer =arr[current -1].topic_answer
    for(let i=0; i<arr.length;i++){
        const Li=
        `
        <li>
            <input type="radio" name="item" id="item1">
            <label for="item1">社交媒体（微信、微博等）</label>
          </li>
        `
    }
}





